package server;

/**
 * @program: minicat
 * @description
 * @author: luffy
 * @create: 2020-08-02 20:37
 */
public class HttpProtocolUtil {
    /**
     * 为响应码200 提供响应头
     * @return
     *
     *
     *
     * HTTP/1.1 200 OK
     * Bdpagetype: 2
     * Bdqid: 0xd1614ebf0010f7ea
     * Cache-Control: private
     * Connection: keep-alive
     * Content-Encoding: gzip
     * Content-Type: text/html;charset=utf-8
     * Date: Sun, 02 Aug 2020 12:42:18 GMT
     * Expires: Sun, 02 Aug 2020 12:42:17 GMT
     * Server: BWS/1.1
     * Set-Cookie: BDSVRTM=527; path=/
     * Set-Cookie: BD_HOME=1; path=/
     * Set-Cookie: H_PS_PSSID=32293_1469_31669_32356_32328_31660_32351_32045_32398_32407_32429_32116_26350_32435_31640; path=/; domain=.baidu.com
     * Strict-Transport-Security: max-age=172800
     * Traceid: 1596372138029867751415087426808914704362
     * X-Ua-Compatible: IE=Edge,chrome=1
     * Transfer-Encoding: chunked
     * */
    public static String getHttpHeader200(int contentLength) {
        return "HTTP/1.1 200 OK \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length:" + contentLength + " \n" +
                "\r\n";

    }

    /**
     * 为404提供请求头信息（包含了数据）
     * @return
     */
    public static String getHttpHeader404() {
        String str404 = "<h1>404 not found</h1>";
        return "HTTP/1.1 404 NOT Found \n" +
                "Content-Type: text/html;charset=utf-8 \n" +
                "Content-Length:" + str404.getBytes().length + " \n" +
                "\r\n" + str404;

    }
}
